//存储好友申请事件
#pragma once
#include <string>
#include <cstddef>
#include <odb/nullable.hxx>
#include <odb/core.hxx>
#include "session_member.hxx"

namespace zzy_mims
{
    enum class ChatSessionType
    {
        SINGLE = 1,
        GROUP = 2 
    };

    #pragma db object table("chat_session")
    class ChatSession 
    {   
    public:
        ChatSession(){};
        ~ChatSession(){};

        ChatSession(const std::string& chat_session_id,const std::string& chat_session_name,const ChatSessionType& chat_session_type)
        :_chat_session_id(chat_session_id),_chat_session_name(chat_session_name),_chat_session_type(chat_session_type){};

        void chat_session_id(const std::string& val){_chat_session_id = val;};
        std::string chat_session_id()
        {
            return _chat_session_id;
        }

        void chat_session_name(const std::string& val){_chat_session_name = val;};
        std::string chat_session_name()
        {
            return _chat_session_name;
        }
        void chat_session_type(const ChatSessionType& val){_chat_session_type = val;};
        ChatSessionType chat_session_type()
        {
            return _chat_session_type;
        }

    private:
        friend class odb::access;

        #pragma db id auto
        unsigned long _id;

        #pragma db type("varchar(64)") index unique
        std::string _chat_session_id;
        #pragma db type("varchar(64)")
        std::string _chat_session_name;
        #pragma db type("tinyint")
        ChatSessionType _chat_session_type;
    };

    #pragma db view object(ChatSession = cs)\
                    object(SessionMember=sm1:cs::_chat_session_id==sm1::_session_id)\
                    object(SessionMember=sm2:cs::_chat_session_id==sm2::_session_id)\
                    query(cs::_chat_session_type==ChatSessionType::SINGLE&&sm1::_user_id!=sm2::_user_id&&(?))
    struct SingleChatSession 
    {
        #pragma db column(cs::_chat_session_id)
        std::string sid;
        #pragma db column(sm2::_user_id)
        std::string friend_id;
    };
    #pragma db view object(ChatSession = cs)\
                    object(SessionMember=sm:cs::_chat_session_id==sm::_session_id)\
                    query(cs::_chat_session_type==ChatSessionType::GROUP&&(?))
    struct GroupChatSession
    {
        #pragma db column(cs::_chat_session_id)
        std::string sid;
        #pragma db column(cs::_chat_session_name)
        std::string sname;
    };


}